package xworker.gluon.netty;

import xworker.netty.NettySession;

import java.util.ArrayList;
import java.util.List;

public class Provider {
    String name;
    String password;
    List<Client> clientList = new ArrayList<>();
    int providerCount = 0;

    public Provider(String name, String password){
        this.name = name;
        this.password = password;
    }

    public void addClient(Client client){
        if(!clientList.contains(client)){
            clientList.add(client);
        }

    }

    public void removeClient(Client client){
        clientList.remove(client);
    }

    public String getName() {
        return name;
    }

    public String getPassword() {
        return password;
    }

    public List<Client> getClientList() {
        return clientList;
    }

    public void attach(NettySession session){
        session.setAttribute("provider", this);
        providerCount++;
    }

    public void onProviderClosed(){
        providerCount--;
    }

    public int getProviderCount() {
        return providerCount;
    }

    public static Provider getProvider(NettySession nettySession){
        return (Provider) nettySession.getAttribute("provider");
    }
}
